package run.newbug.springboot_demo4_mvc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//import run.newbug.springboot_demo4_mvc.mapper.UserMapperInter;
import run.newbug.springboot_demo4_mvc.pojo.User;
import run.newbug.springboot_demo4_mvc.service.UserService;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("getAll")
    public List<User> getAll(){
        return userService.gatAll();
    }

    @RequestMapping("update")
    public List<User> update(@RequestBody User user){
        return userService.update(user);
    }

    @RequestMapping("delete")
    public List<User> delete(Integer id){
        return userService.deleteById(id);
    }

    @RequestMapping("getById")
    public User getById(Integer id){
        return userService.getById(id);
    }

    @RequestMapping("getByUs")
    public List<User> getByUs(User user){
        return userService.getByUs(user);
    }

    @RequestMapping("/kkk/{x}")
    public List<User> getByNameLike(@PathVariable String x){
        return userService.getByNameLike(x);
    }

    @DeleteMapping("deleteByName")
    public List<User> dele(User user){
        if(user != null){
            userService.deleteByName(user);
            return userService.gatAll();

        }else{
            return null;
        }
    }

    @PostMapping("saveUser")
    public List<User> saveUser(@RequestBody User user){
        userService.inser(user);
        return userService.gatAll();
    }

    @PostMapping("saveUser2/{name}/{age}/{sex}")
    public List<User> saveUser2(@RequestBody User user){
        userService.inser(user);
        return userService.gatAll();
    }


}
